package com.gcsoftware.gateway.utils;

import java.io.*;

/**
 * Created by qs on 2018/4/11.
 */
public class FileUtils {
    public static void writeFile(String fileStr , String path) {
        FileOutputStream outSTr = null;
        BufferedOutputStream buff = null;
        try {
            outSTr = new FileOutputStream(new File(path));
            buff = new BufferedOutputStream(outSTr);
            buff.write(fileStr.getBytes());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                buff.flush();
                buff.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }

    public static String readFileAsStr(String path) {
        return null;
    }

    public static String readFileAsStr(File file) {
        FileInputStream fileIn = null;
        BufferedInputStream bis = null;
        byte[] bytes = null;
        String rsp = null;
        try {
            fileIn=new FileInputStream(file);

            int size=fileIn.available();

            bytes=new byte[size];

            fileIn.read(bytes);

            rsp = new String(bytes,"UTF-8");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fileIn.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return rsp;
    }
}
